package string;

public class LengthDemo {
    public static void main(String[] args) {
        /**
         * length 方法返回字符串中字符的个数
         * charAt 获取指定位置的字符
         */
        String str = "Thinking in Java是本好书";
        int length = str.length();
        System.out.println(length); //21
        char ch = str.charAt(12);
        System.out.println(ch); //J
        //统计i字符的个数
        int count = 0;
        for (int i=0; i<str.length(); i++){
            char c = str.charAt(i);
            if (c=='i'){
                count++;
            }
        }
        System.out.println(count); //3
    }
}
